<template>
	<el-dialog title="" visible :show-close="false" :modal-append-to-body="false" class="wrap">
		<div class="bt">修改</div>
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		<el-form label-width="100px" class="form">
			<el-form-item label="项目名称">
				<el-input v-model="form.cdname" placeholder="请输入" class="select-block"></el-input>
			</el-form-item>
			
			<el-form-item label="标签"  v-if="bq">
				<el-input v-model="form.bq" placeholder="请输入标签" class="select-block"></el-input>
			</el-form-item>

			<el-form-item label="是否有效">
				<el-tooltip placement="top" class="sx">
					<el-switch v-model="form.isenable" active-color="#13ce66" inactive-color="#ff4949" inactive-text="否" active-text="是" active-value="Y" inactive-value="N"></el-switch>
				</el-tooltip>
			</el-form-item>

		</el-form>
		<el-button type="primary" class="submit" @click="submit">修改</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		props: ['params'],
		data() {
			return {
				bq:false,
				form: {
					pcd:'',
					cdname: '',
					isenable: '',
					bq:'',
					id: ''
				},
			}
		},
		created() { 
//			alert(this.params.row.pcd)
			this.form.id = this.params.row.id;
			this.loadinfo();
//			alert(this.form.pcd)
			
		},
		methods: {
			loadinfo() {
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					xxid: logininfo.xxid,
					yhid: logininfo.id,
					id: this.form.id
				})
				//执行
				this.axios.post(this.$store.state.api + 'xxcode/info', params2)
					.then(res => { 
						console.log(res,'sss')
						this.form = res.data.data.list[0]
						this.form.pcd=res.data.data.list[0].pcd
						if(this.form.pcd=='c005'){
								this.bq=true;
							}
						 if(this.form.pcd=='c006'){
								this.bq=true;
							}
						
						
					}).catch(res => {
						this.$message.warning("服务器异常");
						this.$emit('close', {type: 'info',cancel: true});
					})
			},
			submit() {
				this.$store.state.loading = true;
				var logininfo = JSON.parse(localStorage.logininfo);
				var params2 = qs.stringify({
					id: this.form.id,
					bq: this.form.bq,
					cdname: this.form.cdname,
					isenable: this.form.isenable,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				//执行
				this.axios.post(this.$store.state.api + 'xxcode/update', params2)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', {type: 'edit',cancel: false});
							this.$store.state.loading = false;
						} else {
							this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器异常");
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', {	type: 'edit',cancel: true})
			},
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		text-align: center;
	}
	
	.bt {
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		margin-bottom: 20px;
		color: white;
		text-align: left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
	
	.form {
		text-align: left;
		margin-top: 20px;
	}
	
	.input {
		display: inline-block;
	}
	
	.select-block {
		display: block;
		width: 85%;
	}
	
	.submit {
		width: 120px;
	}
</style>